<template>
  <div class="chase-wrap">
    <div class="title">追加评价：</div>
    <div class="reason-box">
      <textarea class="reason" v-model="remark" placeholder="您的需要就是蓝聘的追求~" maxlength="150"></textarea>
    </div>

    <div class="btn-box" @click="chaseEvaluate">
      <button type="button" class="btn">确定</button>
    </div>
  </div>
</template>

<script>
  import {baseUrl} from "../../common/js/env"
  import {getUrlKey, getDevice} from "../../common/js/util"

  export default {
    data() {
      return {
        remark: "",
        evaluateId: "",
        workRemarkList: [],
        id: getUrlKey("id"),
        deviceType: ""
      }
    },
    mounted() {
      this.evaluateId = this.$route.query.evaluateId;
      this.deviceType = this.$route.query.deviceType;

      if (this.id) {
        this.userSign = this.id;
      } else {
        let base64 = require('js-base64').Base64;
        this.userSign = base64.decode(sessionStorage.getItem("user_sign"));
      }
    },
    methods: {
      chaseEvaluate() {//追加评论
        if (this.remark == "" || this.remark == undefined) {
          this.$vux.toast.text("请输入评价内容", "middle");
          return;
        }
        this.$vux.loading.show({
          text: '加载中',
        });
        let question = {};
        question.workOrderId = this.evaluateId;
        question.problemName = "追加评价";
        question.problemAnswer = this.remark;
        this.workRemarkList.push(question);

        this.axios.post(baseUrl + "/work/insert_work_remark?sgin=" + this.userSign, this.workRemarkList).then((res) => {
          let resultObj = res.data;
          this.$vux.loading.hide();
          if (resultObj.code == 0) {
            if (resultObj.data == 1) {
              if (this.deviceType != 1) {
                if (getDevice() == "ios") {
                  window.webkit.messageHandlers.submitSuccess.postMessage({
                    "body": "3"
                  });
                } else if (getDevice() == "android") {
                  window.android.submitSuccess(3); //调用安卓
                }
              }
              this.$router.push({
                path: "/entryevaluateedit",
                query: {"evaluateId": this.evaluateId, "id": this.userSign, "deviceType": this.deviceType}
              });
            } else {
              this.$vux.toast.text("追加评价失败，请重试", "middle");
            }
          } else {
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        }).catch(() => {
          this.$vux.loading.hide();
          this.$vux.toast.text("网络异常", "middle");
        });
      }
    }
  }
</script>

<style lang="stylus" scoped>
  @import "../../common/stylus/mixin.styl"

  .chase-wrap
    wh(100%, 100%)
    overflow: hidden
    .title
      display: flex
      align-items: center
      wh(100%, 1.28rem)
      margin-left: 3.2%
      size-color(0.427rem, rgba(51, 51, 51, 1))
      font-weight: 500
    .reason-box
      margin: 0.133rem auto 0.267rem
      wh(9.36rem, 2.667rem)
      border-radius(0.053rem)
      .reason
        wh(97%, 2.4rem)
        padding-left: 0.28rem
        padding-top: 0.28rem
        line-height: 0.48rem
        border: 0.027rem solid #E0E0E0
        size-color(0.373rem, rgba(51, 51, 51, 1))
        resize: none
    .btn-box
      margin-top: 1.067rem
      display: flex
      justify-content: center
      align-items: center
      width: 100%
      height: 1.28rem
      .btn
        width: 90.4%
        height: 1.28rem
        line-height: 1.28rem
        background: rgba(60, 175, 255, 1)
        font-size: 0.453rem
        color: rgba(255, 255, 255, 1)
        font-weight: 500
        border-radius: 0.16rem
</style>
